//
//  BNShowMoodController.m
//  BeautifulNote
//
//  Created by Apple on 2019/7/24.
//  Copyright © 2019 Maker. All rights reserved.
//

#import "BNShowMoodController.h"

@interface BNShowMoodController ()

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UILabel *contentLb;
@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, strong) UILabel *titleLb;

@end

@implementation BNShowMoodController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self initConstaints];
}

- (void)setModel:(BNHomeModel *)model {
    
    self.titleLb.text = [NSString stringWithFormat:@"%@-%@-%@", model.year, model.month, model.day];
    self.contentLb.text = model.content;
    
    CGFloat h = [self.contentLb sizeThatFits:CGSizeMake(ScreenWidth - 60, MAXFLOAT)].height;
    self.contentLb.frame = CGRectMake(10, 10, ScreenWidth - 60, h);
    self.scrollView.contentSize = CGSizeMake(ScreenWidth - 40, h + 20);
}

- (void)clickBackButton {
    [self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark - private methods
- (void)initConstaints {
    
    [self.view addSubview:self.backButton];
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(SafeAreaTopHeight + StatusBarHeight + 15);
        make.width.height.mas_equalTo(25);
    }];
    
    [self.view addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backButton);
        make.left.mas_equalTo(55);
        make.right.mas_equalTo(-55);
    }];
    
    [self.view addSubview:self.scrollView];
    self.scrollView.frame = CGRectMake(20, SafeAreaTopHeight + StatusBarHeight + 50, ScreenWidth - 40, ScreenHeight -(SafeAreaTopHeight + StatusBarHeight + 50 + SafeAreaBottomHeight + 20));
    
    [self.scrollView addSubview:self.contentLb];
}

#pragma mark - getters and setters
- (UIButton *)backButton {
    if (!_backButton) {
        _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [_backButton addTarget:self action:@selector(clickBackButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backButton;
}

- (UILabel *)titleLb {
    if (!_titleLb) {
        _titleLb = [UILabel new];
        _titleLb.font = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:16];
        _titleLb.textColor = [UIColor blackColor];
        _titleLb.textAlignment = NSTextAlignmentCenter;
        _titleLb.text = @"秘密心事";
    }
    return _titleLb;
}

- (UILabel *)contentLb {
    if (!_contentLb) {
        _contentLb = [UILabel new];
        _contentLb.font = lightFont(16);
        _contentLb.textColor = [UIColor blackColor];
        _contentLb.numberOfLines = 0;
    }
    return _contentLb;
}

- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [UIScrollView new];
    }
    return _scrollView;
}

@end
